package com.zpark.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zpark.mapper.GoodsMapper2;
import com.zpark.pojo.Goods;
import com.zpark.pojo.User;
import com.zpark.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    private GoodsMapper2 goodsMapper2;

    @Override
    public List<Goods> findAll() {
        return goodsMapper2.selectAll();
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
    public PageInfo<Goods> queryByPage(Integer curPage, Integer pageSize) {
        PageHelper.startPage(curPage, pageSize);
        List<Goods> goodsList = goodsMapper2.selectAll();
        return new PageInfo<>(goodsList);
    }

    @Override
    public Goods findOne(Integer id) {
        return goodsMapper2.selectByPrimaryKey(id);
    }
}
